var User_Diary_Loader = function () {

    var chuyencan_table = function() {
        var oTable = $('#chuyencan_table').dataTable( {
            "aoColumnDefs": [
            {
                "aTargets": [ 0 ]
            }
            ],
            "aaSorting": [[0, 'asc']],
            "bPaginate": true, // true: Show paging
            "bInfo": false, // true: Show Info
            "aLengthMenu": [
            [5, 15, 20, -1],
            [5, 15, 20, "All"] // change per page values here
            ],
            // set the initial value
            "iDisplayLength": 10,
            "oLanguage": {
                "sEmptyTable": "Chưa có dữ liệu",
                "sLengthMenu": "Hiện _MENU_",
                "sSearch": "Tìm _INPUT_",
                "sInfo": "Hiện _START_ đến _END_ | _TOTAL_",
                "oPaginate": {
                    "sNext": "Tới",
                    "sPrevious": "Lui"
                }
            }
        });

        jQuery('#chuyencan_table_wrapper .dataTables_filter input').addClass("m-wrap small"); // modify table search input
        jQuery('#chuyencan_table_wrapper .dataTables_length select').addClass("m-wrap small"); // modify table per page dropdown
        jQuery('#chuyencan_table_wrapper .dataTables_length select').select2(); // initialize select2 dropdown

        $('#chuyencan_table_column_toggler input[type="checkbox"]').change(function(){
            /* Get the DataTables object again - this is not a recreation, just a get of the object */
            var iCol = parseInt($(this).attr("data-column"));
            var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
            oTable.fnSetColumnVis(iCol, (bVis ? false : true));
        });
    }

    var hocluc_table = function() {
        var oTable = $('#hocluc_table').dataTable( {  
            "aoColumnDefs": [
            {
                "aTargets": [ 0 ]
            }
            ],
            "aaSorting": [[0, 'asc']],
            "bPaginate": true, // true: Show paging
            "bInfo": false, // true: Show Info
            "aLengthMenu": [
            [5, 15, 20, -1],
            [5, 15, 20, "All"] // change per page values here
            ],
            // set the initial value
            "iDisplayLength": 10,
            "oLanguage": {
                "sEmptyTable": "Chưa có dữ liệu",
                "sLengthMenu": "Hiện _MENU_",
                "sSearch": "Tìm _INPUT_",
                "sInfo": "Hiện _START_ đến _END_ | _TOTAL_",
                "oPaginate": {
                    "sNext": "Tới",
                    "sPrevious": "Lui"
                }
            }
        });

        jQuery('#hocluc_table_wrapper .dataTables_filter input').addClass("m-wrap small"); // modify table search input
        jQuery('#hocluc_table_wrapper .dataTables_length select').addClass("m-wrap small"); // modify table per page dropdown
        jQuery('#hocluc_table_wrapper .dataTables_length select').select2(); // initialize select2 dropdown

        $('#hocluc_table_column_toggler input[type="checkbox"]').change(function(){
            /* Get the DataTables object again - this is not a recreation, just a get of the object */
            var iCol = parseInt($(this).attr("data-column"));
            var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
            oTable.fnSetColumnVis(iCol, (bVis ? false : true));
        });
    }

    return {

        //main function to initiate the module
        init: function () {
            
            if (!jQuery().dataTable) {
                return;
            }

            chuyencan_table();
            hocluc_table();
        }
    };

}();